package innersort.speed;

import innersort.insert.InsertSort;
import innersort.insert.ShellSort;
import innersort.merge.MergeSort;
import innersort.radix.RadixSort;
import innersort.select.HeapSort;
import innersort.select.SelectSort;
import innersort.swap.BubbleSort;
import innersort.swap.QuickSort;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-06-03 16:13
 * @ Description :
 */
public class SpeedTest
{
    //数据量
    private static final int QN = 8000000;


    public static void main(String[] args)
    {
        System.out.println("直接插入排序:");
        speedTest(new InsertSort());
        System.out.println("希尔排序");
        speedTest(new ShellSort());

        System.out.println("选择排序");
        speedTest(new SelectSort(),true);
        System.out.println("堆排序");
        speedTest(new HeapSort());

        System.out.println("冒泡排序");
        speedTest(new BubbleSort());
        System.out.println("快速排序");
        speedTest(new QuickSort());

        System.out.println("归并排序");
        speedTest(new MergeSort());

        System.out.println("基数排序");
        speedTest(new RadixSort());


    }

    public static void speedTest(SortStrategy sortStrategy,boolean hook)
    {
        int[] array = new int[QN];
        for (int i = 0; i < QN; i++)
        {
            array[i] = (int)(Math.random() * 100000);
        }
        if (hook)
        {
            System.out.println(Arrays.toString(array));
        }

        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String beforeSort = format.format(date);
        System.out.println("beforeSort = " + beforeSort);

        sortStrategy.sort(array);

        Date date1 = new Date();
        String afterSort = format.format(date1);
        System.out.println("afterSort = " + afterSort);
    }


    public static void speedTest(SortStrategy sortStrategy)
    {
        speedTest(sortStrategy,false);
    }



}
